package com.bjqg.bjqg01.bjqg.activity;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bjqg.bjqg01.bjqg.R;

/**
 * Created by bjqg01 on 2017/12/14.
 */

public class SettingActivity extends BaseActivity implements View.OnClickListener {

    private RelativeLayout epmanage;
    private ImageView goback;
    private TextView toptitle;
    private ImageView select;
    private TextView versionCode;
    private PackageInfo info;
    private RelativeLayout testUpdate;
    private RelativeLayout onselfcenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        initView();
    }

    private void initView() {
        goback = (ImageView) findViewById(R.id.back);
        toptitle = (TextView) findViewById(R.id.tv_top_title);
        select = (ImageView) findViewById(R.id.select);
        epmanage = (RelativeLayout) findViewById(R.id.entrust_persion_manage);
        testUpdate = (RelativeLayout) findViewById(R.id.test_update);
        versionCode = (TextView) findViewById(R.id.version_code);
        onselfcenter = (RelativeLayout) findViewById(R.id.onself_center);


        toptitle.setText("设置中心");
        versionCode.setText("当前版本:"+getVersionCode());
        select.setVisibility(View.GONE);
        epmanage.setOnClickListener(this);
        testUpdate.setOnClickListener(this);
        onselfcenter.setOnClickListener(this);
        goback.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.entrust_persion_manage:
                Intent intent = new Intent(getApplicationContext(), ClientManageActivity.class);
                startActivity(intent);
                break;
            case R.id.back:
                finish();
                break;
            case R.id.test_update:
                Toast.makeText(getApplicationContext(),"当前版本已经是最新版本",Toast.LENGTH_SHORT).show();
                break;
            case R.id.onself_center:
                Intent intent1 = new Intent(getApplicationContext(), MyActivity.class);
                startActivity(intent1);
                break;
        }
    }
    //版本号
    public String getVersionCode() {
        try {
            info = getApplicationContext().getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), PackageManager.GET_CONFIGURATIONS);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return info.versionName;
    }
}
